package com.tarena.lbs.basic.web.service.impl;


import com.tarena.lbs.base.protocol.pager.BasePageList;
import com.tarena.lbs.basic.web.repository.AdminRepository;
import com.tarena.lbs.basic.web.service.IAdminService;
import com.tarena.lbs.common.passport.principle.UserPrinciple;
import com.tarena.lbs.common.security.utils.LbsSecurityContenxt;
import com.tarena.lbs.pojo.basic.bo.AdminBO;
import com.tarena.lbs.pojo.basic.param.AdminParam;
import com.tarena.lbs.pojo.basic.query.AdminQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements IAdminService {

    @Autowired
    private AdminRepository adminRepository;


    @Override
    public void insert(AdminParam adminParam) {
        int row=adminRepository.insert(adminParam);
        //TODO 添加去重
    }

    @Override
    public void deleteById(Integer id) {
        adminRepository.deleteById(id);
    }

    @Override
    public AdminBO getAdminById(Integer id) {
        //适配登陆用户
        if (id == null) {
            UserPrinciple loginUser = LbsSecurityContenxt.getLoginToken();
            if (loginUser != null) {
                id = loginUser.getId();
            }
        }
        return adminRepository.getAdminById(id);
    }
    @Override
    public void resetPasswordById(Integer id) {
        adminRepository.resetPasswordById(id);
    }

    @Override
    public void assignRoles(Integer id, Integer accountType) {
        adminRepository.assignRoles(id,accountType);
    }

    @Override public BasePageList<AdminBO> userList(AdminQuery adminQuery) {
        return adminRepository.userList(adminQuery);
    }
}
